#pragma once
#include <iostream>
#include <pthread.h>
using namespace std;
namespace ve
{
    class Mutex
    {
    private:
        pthread_mutex_t _mutex;

    public:
        Mutex()
        {
            pthread_mutex_init(&_mutex, nullptr);
        }
        ~Mutex()
        {
            pthread_mutex_destroy(&_mutex);
        }
        void lock()
        {
            int n = pthread_mutex_lock(&_mutex);
            (void)n;
        }
        void unlock()
        {
            int n = pthread_mutex_unlock(&_mutex);
            (void)n;
        }
    };
    class lockguard
    {
    private:
        Mutex _mutex;
    public:
        lockguard(Mutex &mutex):_mutex(mutex)
        {
            _mutex.lock();
        }
        ~lockguard()
        {
            _mutex.unlock();
        }
    };
}
